<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
       <a-button type="primary" @click="handleCreate" v-auth="'ACTION_help_add'">新增</a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"  :dropDownActions="getDropDownAction(record)"/>
      </template>
    </BasicTable>
    <Drawer @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup name="help">
import { BasicTable, TableAction, ActionItem } from '@apps/antd-admin/src/components/Table';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import Drawer from './components/drawer.vue';
import { columns, searchFormSchema } from './data/data';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { Api } from './data/api';
const [registerDrawer, { openDrawer }] = useDrawer();

const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'help-template',
  tableProps: {
    rowKey: 'htmlId',
    title: '帮助中心',
    listUrl: Api.page,
    delUrl: Api.remove,
    handlerName: 'sysHelpListHandler',
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
  },
});
const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '编辑',
      icon: 'clarity:note-edit-line',
      auth:'ACTION_help_edit',
      onClick: handleEdit.bind(null, record),
    },
  ];
}

/**
 * 下拉操作栏
 */
function getDropDownAction(record): ActionItem[] {
  return [
    {
      label: '删除',
      auth:'ACTION_help_del',
      popConfirm: {
        title: '是否确认删除',
        icon: 'ant-design:delete-outlined',
        confirm: handleDelete.bind(null, record),
      },
    },
  ];
}

function handleCreate() {
  openDrawer(true, {
    isUpdate: false,
  });
}

function handleEdit(record: Recordable) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}
</script>
